//
//  XZPunchCardCell.m
//  Teecloud
//
//  Created by PC on 2018/11/29.
//  Copyright © 2018年 小志. All rights reserved.
//

#import "XZPunchCardCell.h"

@implementation XZPunchCardCell



- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}
- (void)setModel:(XZWorkTimeInfo *)model{
    _model = model;
    self.nameAndTimeLabel.text = [NSString stringWithFormat:@"%@  %@",model.Name,model.TimeName];
    
    if (!model.IsClockEnable) {
        self.circleView.backgroundColor = [UIColor colorWithHexString:@"9A9A9A" andAlpha:1.0f];
    }else{
        self.circleView.backgroundColor = [UIColor colorWithHexString:@"196EE6" andAlpha:1.0f];
    }
    
    //GPS为空隐藏
    if (kIsEmptyString(model.GpsAddress)) {
        self.addressImg.hidden = YES;
        self.addressLabel.hidden = YES;
    }else{
        self.addressImg.hidden = false;
        self.addressLabel.hidden = false;
        self.addressLabel.text = model.GpsAddress;
    }
    
    //wifi为空隐藏
    if (kIsEmptyString(model.WifiName)) {
        self.wifiImg.hidden = YES;
        self.wifiLabel.hidden = YES;
    }else{
        self.wifiImg.hidden = false;
        self.wifiLabel.hidden = false;
        self.wifiLabel.text = model.WifiName;
    }
    
    
    //打卡时间
    if (kIsEmptyString(model.ClockTime)) {
        self.clockTimeLabel.hidden = true;
        //将btn1前移
        [self.btn1 mas_updateConstraints:^(MASConstraintMaker *make) {
            make.leading.mas_equalTo(self.nameAndTimeLabel);
        }];
    }else{
        self.clockTimeLabel.hidden = false;
        self.clockTimeLabel.text = [NSString stringWithFormat:@"%@",model.ClockTime];
    }
    //btn1
    if (!kIsEmptyString(model.ClockStatusName)) {
        self.btn1.hidden = false;
        [self.btn1 setTitle:model.ClockStatusName forState:0];
        if ([model.ClockStatusName isEqualToString:@"请假"]) {
            [self.btn1 setTitleColor:kWhiteColor forState:UIControlStateNormal];
            [self.btn1 setBackgroundColor:kFF8700Color];
        }else if ([model.ClockStatusName isEqualToString:@"正常"]){
            [self.btn1 setTitleColor:k1168E6Color forState:UIControlStateNormal];
            self.btn1.layer.borderWidth = 0.5f;
            self.btn1.layer.borderColor = k1168E6Color.CGColor;
            
        }else if ([model.ClockStatusName isEqualToString:@"缺卡"]){
            [self.btn1 setTitleColor:kRedColor forState:UIControlStateNormal];
            self.btn1.layer.borderWidth = 0.5f;
            self.btn1.layer.borderColor = kRedColor.CGColor;
        }else if ([model.ClockStatusName isEqualToString:@"迟到"] || [model.ClockStatusName isEqualToString:@"早退"]){
            [self.btn1 setTitleColor:kFF8700Color forState:UIControlStateNormal];
            self.btn1.layer.borderWidth = 0.5f;
            self.btn1.layer.borderColor = kFF8700Color.CGColor;
        }
    }else{
        self.btn1.hidden = true;
    }
    
    //btn2
    if (!kIsEmptyString(model.NamingStatusName)) {
        self.btn2.hidden = false;
        //如ClockStatusName && ClockTime都为空就前移到nameAndTimeLabel等边距
        if (kIsEmptyString(model.ClockStatusName) && kIsEmptyString(model.ClockTime)) {
            [self.btn2 mas_updateConstraints:^(MASConstraintMaker *make) {
                make.leading.mas_equalTo(self.nameAndTimeLabel);
            }];
        }
         //如ClockStatusName为空就前移到btn1位置上去
        if (kIsEmptyString(model.ClockStatusName) && !kIsEmptyString(model.ClockTime)) {
            [self.btn2 mas_updateConstraints:^(MASConstraintMaker *make) {
                make.left.mas_equalTo(self.clockTimeLabel.mas_right).offset(10);
            }];
        }
        
        if ([model.NamingStatusName isEqualToString:@"请假"]) {
            [self.btn2 setTitleColor:kFF8700Color forState:UIControlStateNormal];
            self.btn2.layer.borderWidth = 0.5f;
            self.btn2.layer.borderColor = kFF8700Color.CGColor;
        }else if ([model.NamingStatusName isEqualToString:@"已到"]){
            [self.btn2 setTitleColor:k1168E6Color forState:UIControlStateNormal];
            self.btn2.layer.borderWidth = 0.5f;
            self.btn2.layer.borderColor = k1168E6Color.CGColor;
            
        }else if ([model.NamingStatusName isEqualToString:@"未到"]){
            [self.btn2 setTitleColor:kRedColor forState:UIControlStateNormal];
            self.btn2.layer.borderWidth = 0.5f;
            self.btn2.layer.borderColor = kRedColor.CGColor;
            
        }
        
    }else{
        self.btn2.hidden = true;
    }
    
}

//请假
- (IBAction)leaveBtnAction:(UIButton *)sender {
    NSString *text = sender.titleLabel.text;
    if ([text isEqualToString:@"请假"]) {
        if (self.leaveBlock) {
            self.leaveBlock(self.model);
        }
    }
}


@end
